/*
 * independent method
 */
function Support() {
}

var oldSetInterval = window.setInterval;
var oldClearInterval = window.clearInterval;
window.intervals = [];
window.setInterval = function(func, time) {
	var id = oldSetInterval(func, time);
	window.intervals.push(id);
	return id;
}

window.clearInterval = function(id) {
	oldClearInterval(id);
	for (var i = 0; i < window.intervals.length; ++i)
		if (window.intervals[i] == id)
			window.intervals.splice(i, 1);

}
window.isIntervalRegistered = function(id) {
	for (var i = 0; i < window.intervals.length; ++i)
		if (window.intervals[i] == id)
			return true;
	return false;
}

Support.validateNumber = function(evt) {
	var e = evt || window.event;
	var key = e.keyCode || e.which;

	if (!e.shiftKey && !e.altKey && !e.ctrlKey &&
	// numbers
	key >= 48 && key <= 57 ||
	// Numeric keypad
	key >= 96 && key <= 105 ||
	// Backspace and Tab and Enter
	key == 8 || key == 9 || key == 13 ||
	// Home and End
	key == 35 || key == 36 ||
	// left and right arrows
	key == 37 || key == 39 ||
	// Del and Ins
	key == 46 || key == 45) {
		// input is VALID
	} else {
		// input is INVALID
		e.returnValue = false;
		if (e.preventDefault)
			e.preventDefault();
	}
}
/*
 * Date 18/08/2013 copy from
 * http://robertnyman.com/2006/04/24/get-the-rendered-style-of-an-element/
 */
Support.getStyle = function(oElm, strCssRule) {
	var strValue = "";
	if (document.defaultView && document.defaultView.getComputedStyle) {
		strValue = document.defaultView.getComputedStyle(oElm, "")
				.getPropertyValue(strCssRule);
	} else if (oElm.currentStyle) {
		strCssRule = strCssRule.replace(/\-(\w)/g, function(strMatch, p1) {
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}

Support.pointerInComponent = function(e, node) {
	var x = 0;
	var y = 0;
	if (e.pageX || e.pageY) {
		x = e.pageX;
		y = e.pageY;
	} else if (e.clientX || e.clientY) {
		x = e.clientX + document.body.scrollLeft
				+ document.documentElement.scrollLeft;
		y = e.clientY + document.body.scrollTop
				+ document.documentElement.scrollTop;
	}

	var top = node.offsetTop;
	var left = node.offsetLeft;
	var height = node.clientHeight;
	var width = node.clientWidth;

	if (y <= top || y >= top + height || x <= left || x >= left + width) {
		return false;
	} else {
		return true;
	}

}

Support.goToCategory = function(categoryId) {
	window.location.href = '/show_room/' + categoryId
};